<template>
  <div class="register">
    <van-nav-bar
      title="登录"
      left-arrow
      @click-left="$router.back()"
    ></van-nav-bar>
    <FormSubmit @submit="onSubmit"></FormSubmit>
  </div>
</template>

<script>
import * as Types from "@/store/action-types.js";
import { createNamespacedHelpers } from "vuex";
import FormSubmit from "@/components/form-submit.vue";
import { Dialog } from "vant";
let { mapActions } = createNamespacedHelpers("user");
export default {
  components: {
    FormSubmit,
  },
  data() {
    return {
      username: "",
      password: "",
    };
  },
  methods: {
    ...mapActions([Types.SET_LOGIN]),
    async onSubmit(value) {
      //   console.log("提交");
      //   console.log(value);
      try {
        await this[Types.SET_LOGIN](value);
        this.$router.push("/profile");
      } catch (e) {
        Dialog.alert({
          title: "登录失败",
          message: e.data,
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped></style>
